/*
 * Copyright 2012 NJUT  qixiaobo. All rights reserved.
 */
package com.fujitsu.nanjing.tieba.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fujitsu.nanjing.tieba.base.BaseService;
import com.fujitsu.nanjing.tieba.constrant.CommonParamter;
import com.fujitsu.nanjing.tieba.ibator.CoreGroup;
import com.fujitsu.nanjing.tieba.ibator.CoreGroupCriteria;
import com.fujitsu.nanjing.tieba.model.Group;

/**
 * GroupService.java
 * 
 * @author Qixiaobo-win8
 */
@Service
@Transactional
public class GroupService extends BaseService<CoreGroup, CoreGroupCriteria> {
	@Resource
	private Group group;
	@Override
	public CoreGroup findById(String id) {
		return group.selectByPrimaryKey(id);

	}

	@Override
	public CoreGroup insert(CoreGroup t) {
		t.setGroupid(group.insertSelective(t));
		return t;
	}

	@Override
	public void update(CoreGroup t) {
		group.updateByPrimaryKey(t);

	}

	@Override
	public void delete(CoreGroup t) {
		group.deleteByPrimaryKey(t.getGroupid());

	}

	public String findCeilGroupId(int score) {
		return group.getCeilGroupId(score);
	}

	public boolean isUserType(String groupId) {
		return findById(groupId).getGrouptype().equals(CommonParamter.用户类型);
	}

	public List<CoreGroup> findAllGroups() {
		CoreGroupCriteria example = new CoreGroupCriteria();
		example.createCriteria().andGroupidIsNotNull();
		return group.selectByExample(example);
	}

	public List<CoreGroup> findAdminGroups() {
		CoreGroupCriteria example = new CoreGroupCriteria();
		example.createCriteria().andGrouptypeEqualTo("S");
		return group.selectByExample(example);
	}

}
